
var element = layui.element;
$ (document).on( 'click', '#xungengid', function(){
    // layer.msg("点击了个人资料");
    layer.open({
        type: 2,
        area:['80%','90%'],
        content:"baobiao1.html" ,//不想让iframe出现滚动可以content: ['http://sentsin.com', 'no']
        title: ['按巡更人ID查询', 'font-size:18px;'],
        shade:['0.2','red']
    });
});

$(document).on( 'click', '#xungengsum', function(){
    layer.open({
        type: 2,
        area:['80%','90%'],
        content: "baobiao2.html" ,//不想让iframe出现滚动可以content: ['http://sentsin.com', 'no']
        title: ['按巡更人总数查询', 'font-size:18px;'],
        shade:['0.2','red']
    });
});
$(document).on( 'click', '#fengxianid', function(){
    layer.open({
        type: 2,
        area:['80%','90%'],
        content: "baobiao3.html" ,//不想让iframe出现滚动可以content: ['http://sentsin.com', 'no']
        title: ['按巡更id查询', 'font-size:18px;'],
        shade:['0.2','red']
    });
});
$(document).on( 'click', '#fengxiantotal', function(){
    layer.open({
        type: 2,
        area:['80%','90%'],
        content: "baobiao4.html" ,//不想让iframe出现滚动可以content: ['http://sentsin.com', 'no']
        title: ['按巡更时段查询', 'font-size:18px;'],
        shade:['0.2','red']
    });
});
$(document).on( 'click', '#xungengrenyuanchaxun', function(){
    layer.open({
        type: 2,
        area:['80%','90%'],
        content: "xungenrenyuan.html" ,//不想让iframe出现滚动可以content: ['http://sentsin.com', 'no']
        title: ['按巡更时段查询', 'font-size:18px;'],
        shade:['0.2','red']
    });
});
$(document).on( 'click', '#shijianduan', function(){
    layer.open({
        type: 2,
        area:['80%','90%'],
        content: "shijianduan.html" ,//不想让iframe出现滚动可以content: ['http://sentsin.com', 'no']
        title: ['按巡更时段查询', 'font-size:18px;'],
        shade:['0.2','red']
    });
});

$(document).on( 'click', '#userinfo', function(){
    layer.open({
        type: 2,
        area:['80%','90%'],
        content: "userinfo.html" ,//不想让iframe出现滚动可以content: ['http://sentsin.com', 'no']
        title: ['派遣巡更人员', 'font-size:18px;'],
        shade:['0.2','red']
    });
});
$(document).on( 'click', '#baobiaototal', function(){
    layer.open({
        type: 2,
        area:['90%','90%'],
        content: "baobiaototal.html" ,//不想让iframe出现滚动可以content: ['http://sentsin.com', 'no']
        title: ['报表导出', 'font-size:18px;'],
        shade:['0.2','red']
    });
});

$(document).on( 'click', '#chakanxungeng', function(){
    layer.open({
        type: 2,
        area:['80%','90%'],
        content: "xungengjilu.html" ,//不想让iframe出现滚动可以content: ['http://sentsin.com', 'no']
        title: ['巡更记录查看', 'font-size:18px;'],
        shade:['0.2','red']
    });
});
var flag=1;


function show()
{
    myp=[];
    flagx=1;
    document.getElementById('cars').className='pp';
    document.getElementById('run').className='pp';
    document.getElementById('ride').className='pp';
    document.getElementById('setpoint').className='pp';


    flag++;

    if(flag%2==0)
    {
        document.getElementById('watch').className='layui-btn';
        model=flags;
        document.getElementById('xx').style.display='block';
        document.getElementById('controller').style.display='none';
        document.getElementById('plarou').style.display='none';
        document.getElementById('choicepoint').style.display='none';
        document.getElementById("danger").style.display='none';
        mp.clearOverlays();

    }
    else
    {
        document.getElementById('xx').style.display='none';
        document.getElementById('watch').className='pp';
    }



}
function planroute(){
    flag=1;
    document.getElementById('cars').className='layui-btn';
    document.getElementById('run').className='layui-btn';
    document.getElementById('ride').className='layui-btn';
    document.getElementById('xx').style.display='none';
    document.getElementById('plarou').style.display='block';//显示控件按钮
    document.getElementById('controller').style.display='none';
    document.getElementById('choicepoint').style.display='none';
    document.getElementById("danger").style.display='none';
    document.getElementById('begins').disabled=true; }

function choose()
{
    myp=[];
    mp.clearOverlays();
    flagx=1;
    layer.open({
        type: 1,
        area:['28%','80%'],
        content: $('#choice') ,
        title: ['请选择你要查看的人员', 'font-size:18px;'],
        shade:['0.2','red'],

        cancel:function() {
            $('#choice').hide();
        }  })


}

function dangers()
{
    myp=[];
    mp.clearOverlays();
    flagx=1;
    document.getElementById("danger").style.display='block';
    document.getElementById('xx').style.display='none';
    document.getElementById('controller').style.display='none';
    document.getElementById('plarou').style.display='none';
    document.getElementById('choicepoint').style.display='none';
}
function exitend(){
    document.getElementById("danger").style.display='none';
}
function exits(){
    myp=[];
    flagx=1;
    document.getElementById('cars').className='pp';
    document.getElementById('run').className='pp';
    document.getElementById('ride').className='pp';
    document.getElementById('plarou').style.display='none';//关闭显示控件按钮
    mp.clearOverlays();
}
function time(){
    layer.open({
        type: 1,
        area:['28%','70%'],
        content: $('#idea') ,
        title: ['全程查询结果', 'font-size:18px;'],
        shade:['0.2','red'],

        cancel:function() {
            $('#idea').hide();
        }  })
    var oGl = document.getElementById("div_gongli");
    var ofname = document.getElementById("farea");
    var otname = document.getElementById("tarea");
    var output = "全程：";
    var searchComplete = function(results) {
        if (transit.getStatus() != BMAP_STATUS_SUCCESS) { return; }
        var plan = results.getPlan(0);
        output += plan.getDistance(true);       //获取距离
        output += "/";
        output += plan.getDuration(true);        //获取时间
    }
    var transit = new BMap.DrivingRoute(mp, { renderOptions: { mp: mp, panel: "results", autoViewport: true },
        onSearchComplete: searchComplete,
        onPolylinesSet: function() { oGl.innerText = output; }
    });
    transit.search(starts,ends);

}
function times()
{
    var oGl = document.getElementById("div_gongli");
    var ofname = document.getElementById("farea");
    var otname = document.getElementById("tarea");
    var output = "全程：";
    if (ofname.value == "") {
        alert('请输入出发地！');
        return;
    }
    if (otname.value == "") {
        alert('请输入到达地!');
        return;
    }


    var searchComplete = function(results) {
        if (transit.getStatus() != BMAP_STATUS_SUCCESS) { return; }
        var plan = results.getPlan(0);
        output += plan.getDistance(true);       //获取距离
        output += "/";
        output += plan.getDuration(true);        //获取时间
    }
    var transit = new BMap.DrivingRoute(mp, { renderOptions: { mp: mp, panel: "results", autoViewport: true },
        onSearchComplete: searchComplete,
        onPolylinesSet: function() { oGl.innerText = output; }
    });
    transit.search(ofname.value, otname.value);
}
function point1() {

    var fields = $('#gaopoint').serializeArray();
    var obj = {}; //声明一个对象
    $.each(fields, function(index, field) {
        obj[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
    })
    $.ajax({
        url:"/fx/insert",
        data:JSON.stringify(obj),
        method: 'POST',
        contentType: 'application/json',
        dataType: "json",
        crossDomain:true,
        success:function(res) {

            if(res.code == 200) {
                layer.msg("派遣人员成功");
            }
            else{
                layer.msg("派遣人员失败，当前任务点已经有人执行");
            }
        }
    })

}
function send() {

    var fields = $('#fxry').serializeArray();
    var objt = {}; //声明一个对象
    $.each(fields, function(index, field) {
        objt[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
    })
    $.ajax({
        url:"/api/taskpoint/allotPoint",
        data:JSON.stringify(objt),
        method: 'POST',
        contentType: 'application/json',
        dataType: "json",
        crossDomain:true,
        success:function(res) {

            if(res.code == 200) {
                layer.msg("派遣成功");
            }
            else{
                layer.msg("派遣失败，当前任务点已经派遣人员");
            }
        }
    })
}
